import request from "@/utils/request";

export async function queryList(
  params: {
    // query
    /** current */
    current?: number;
    /** pageSize */
    pageSize?: number;
  },
  options?: { [key: string]: any },
) {
  const res = await request('/score', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
  console.log('res.data',res.data)
  return {
    success: res.data.records && res.data.records.length >= 0,
    data: res.data.records ?? [],
    total: res.data.total ?? 0
  }
}

export async function queryListCollection(
  params: {
    /** current */
    current?: number;
    /** pageSize */
    pageSize?: number;
    sStuid?: string,
    sStuname?: string,
  },
  options?: { [key: string]: any },
) {
  const res = await request('/score/c', {
    method: 'GET',
    params: {
      stuId: params.sStuid,
      stuName: params.sStuname
    },
    ...(options || {}),
  });
  console.log('res.data', res.data)
  return {
    success: res.data && res.data.length >= 0,
    data: res.data ?? [],
  }
}

export async function add(
  body?: Partial<API.ScoreType>,
  options?: { [key: string]: any },
) {
  return request('/score', {
    method: 'POST',
    data: body,
    ...(options || {}),
  });
}

export async function getDetail(
  params: {
    // path
    /** userId */
    rId: string;
  },
  options?: { [key: string]: any },
) {
  const { rId: param0 } = params;
  return request(`/score/${param0}`, {
    method: 'GET',
    params: { ...params },
    ...(options || {}),
  });
}

export async function modify(
  body?: Partial<API.ScoreType>,
  options?: { [key: string]: any },
) {
  return request(`/score`, {
    method: 'PUT',
    data: body,
    ...(options || {}),
  });
}

export async function remove(
  data: {
    ids: string[]
  },
  options?: { [key: string]: any },
) {

  return request(`/score`, {
    method: 'DELETE',
    data: data.ids,
    ...(options || {}),
  });
}

export async function removeById(
  id: string,
  options?: { [key: string]: any },
) {
  return request(`/score/${id}`, {
    method: 'DELETE',
    ...(options || {}),
  });
}